$(document).ready(function(){
    // alert("dsds");
    $.ajax({
        url:'/index/menus',
        type:'post',
        success:function (data) {
            if (data!=null){
                var mlistobj=JSON.parse(data) ;//把json字符串变为json对象
                var res=""; //临时变量 记录拼接的左菜单内容
                //遍历左边一级二级菜单
                for(var i=0;i<mlistobj.length;i++){
                    //拼接一级菜单
                    var pic;
                    switch(i){
                        case 0:
                            pic="layui-icon left-nav-li";
                            break;
                        case 1:
                            pic="iconfont icon-dashaxiaoqudizhi01";
                            break;
                        case 2:
                            pic="layui-icon iconfont icon-lvhuaxiaoqu";
                            break;
                        case 3:
                            pic="layui-icon iconfont icon-yezhuxian";break;
                        case 4:
                            pic="layui-icon iconfont icon-tingchewei";break;
                        case 5:
                            pic="layui-icon iconfont icon-fuwu";break;
                        case 6:
                            pic="layui-icon iconfont icon-zichan";break;
                        case 7:
                            pic="layui-icon iconfont icon-shoufeizhan";break;
                        case 8:
                            pic="layui-icon iconfont icon-bar";break;
                        case 9:
                            pic="layui-icon  iconfont";break;
                        default:
                            pic="layui-icon iconfont";break;
                    }
                    res=res+'<li class="layui-nav-item" onclick="$(\'#u'+i+'\').toggle(500)"> <a class="javascript:;" href="javascript:;"><i class="'+pic+'" style="top: 3px;"></i><cite>'+mlistobj[i].mainMenu.function_name+'</cite></a>';
                    res=res+'<dl class="layui-nav-child" id=\"u'+i+'\"><dd class="">';
                    for(var j=0;j<mlistobj[i].subMenus.length;j++){
                        res=res+'<dd class="" > <a href="'+mlistobj[i].subMenus[j].function_url+'"><cite>'+mlistobj[i].subMenus[j].function_name+'</cite> </a> </dd>';
                    }
                    res=res+' </dd></dl>';
                }
                res=res+'</li>';
                $("#menus").append(res); //将拼接好的左菜单 追加到id=mainui的ul里
            }
        }

    });


});

$(function () {

    function href(url) {

        $.ajax({
            type:'get',
            url:url,
            success:function () {

            }
        })
    }
})